/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = ora_datadescriptor.c                               */
/*  NOTE      =                                                    */
/*  DATE      = 2015/03/17 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>

#include "frcomm.h"
#include "frstr.h"
#include "frlog.h"

#include "conntrack.h"
#include "frct_comm.h"

#include "../comm/ora_comm.h"
#include "../ora_core.h"
#include "ora_datadescriptor.h"
#include "../ttc/ora_mar_engine.h"
#include "../comm/ora_util.h"

FR_STATIC int __toUb4(char *p_data, int offset) {
    int i = 0;
    int j = 0;
    int k = 0;
    for (j = 0; j < 4; j++) {
        k = (3 - j) * 8;
        i += ((p_data[(j + offset)] & 0xFF) << k);
    }
    return i;
}

/*******************************************************************************
*  FUNC     :  解析accept包，设置TNS版本号、largeSDUFlag、sdu
*  ARGS     :  *p_st_conn                           (ct信息)
*           :  *p_st_sess                           (Oracle私有的session)
*           :  *p_st_ora_packet                     (Oracle数据包)
*  RTN      :  0                                    (FR_SUCC)
*              1                                    (FR_FAIL)
*  NOTE     :
*******************************************************************************/
int ora_datadescriptor_unpack(L7session_ora *p_st_sess
                            , char *p_payload
                            , unsigned int ui_payload_len
                            , int *p_i_datalen)
{
    if (ui_payload_len < 16)
        return FR_FAIL;

    *p_i_datalen = __toUb4(p_payload, 12);

    return FR_SUCC;
}
